package cn.valorin.event;

import static cn.valorin.configuration.languagefile.MessageSender.sm;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;

import cn.valorin.item.RawZongzi;
import cn.valorin.item.RawZongzi2;
import cn.valorin.util.CheckLore;
import cn.valorin.via.Via;

public class LeafEvent implements Listener {
	@SuppressWarnings("deprecation")
	@EventHandler
	public void click(InventoryClickEvent e) {
		Player player = (Player) e.getWhoClicked();
		if (CheckLore.check(e.getCursor(),RawZongzi.get(player))) {
			if (e.getCursor().getAmount() == 1) {
				if (e.getCurrentItem() == null) { return; }
				if (e.getCurrentItem().getType().equals(Via.leaves)) {
					e.setCancelled(true);
					e.setCursor(new ItemStack(Material.AIR));
					e.setCurrentItem(new ItemStack(RawZongzi2.get(player)));
					player.updateInventory();
					sm("&a包裹成功",player);
				}
			} else {
				sm("&c请将粽子拆分成单个",player);
			}
		}
	}
}
